<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>详情页</title>
    <script src="../../js/vue.js"></script>
    <script src="../../js/axios.js"></script>
</head>
<style>
    * {
        margin: 0;
        padding: 0;
        list-style: none;
    }

    .box {
        width: 1226px;
        margin: 100px auto;
    }

    .left {
        width: 400px;
        height: 500px;
        position: relative;
    }

    .top {
        width: 400px;
        height: 400px;
    }

    .top img {
        width: 100%;
        height: 100%;
    }

    .shadow {
        width: 200px;
        height: 200px;
        position: absolute;
        top: 0;
        left: 0;
        background-color: rgba(0, 0, 0, 0.5);
    }
</style>

<body>
    <div id="app">
        <div class="box">
            <div class="left">
                <div class="top" @mousemove="move" id="top">
                    <img src="https://gd1.alicdn.com/imgextra/i1/71202270/O1CN01rJ6uXK1SdhkfxIMtG_!!71202270.jpg"
                        alt="">
                    <div class="shadow" id="shadow" :style="shadowStyle"></div>
                </div>
                <div class="imglist">

                </div>
            </div>
        </div>
    </div>
</body>
<script>
    new Vue({
        el: "#app",
        data: {
            shadowStyle: "",
        },
        mounted() {
            this.topDiv = document.getElementById("top");
            this.shadowDiv = document.getElementById("shadow");
            this.letf = this.topDiv.offsetLeft;
            this.top = this.topDiv.offsetTop;
            this.shadowWidth = this.shadowDiv.offsetWidth;
            this.topWidth = this.topDiv.offsetWidth;

        },
        methods: {
            move() {
                let clientX = window.event.clientX;
                let clientY = window.event.clientY;

                let x = clientX - this.letf - this.shadowWidth / 2;
                let y = clientY - this.top - this.shadowWidth / 2;
                let max = this.topWidth - this.shadowWidth;

                if (x < 0) x = 0;
                if (x > max) x = max;
                if (y < 0) y = 0;
                if (y > max) y = max;

                this.shadowStyle = {
                    left: x + "px",
                    top: y + "px"
                }


            }

        },
    })
</script>

</html>